package org.msfj.admin.api;

import cn.hutool.core.collection.CollectionUtil;
import org.msfj.admin.feign.MenuApi;
import org.msfj.admin.org.service.MenuService;
import org.msfj.admin.vo.MenuVo;
import org.msfj.admin.feign.MenuApi;
import org.msfj.admin.org.service.MenuService;
import org.msfj.admin.vo.MenuVo;
import org.msfj.admin.feign.MenuApi;
import org.msfj.admin.org.service.MenuService;
import org.msfj.admin.vo.MenuVo;
import org.msfj.common.model.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description:
 * @Author: like
 * @Date: 2017-11-03 9:16
 * @Version: 1.0
 * @Created in idea by autoCode
 */
@RestController
public class MenuImplApi implements MenuApi {
    @Autowired
    private MenuService menuService;

    @Override
    public CommonResult<List<String>> getAllPermission() {
        List<MenuVo> allMenu = menuService.getAllMenu(null);
        List<String> premissions = CollectionUtil.newArrayList();
        if (CollectionUtil.isNotEmpty(allMenu)) {
            for (MenuVo menu : allMenu) {
                if (!menu.getPermission().contains(":")) { // 没有冒号的直接跳过
                    continue;
                }
                for (String perm : menu.getPermission().split(",")) {
                    premissions.add(menu.getPermission());
                }
            }
        }
        return CommonResult.ok(premissions);
    }
}
